/**
 * 
 */
package vy.org.app.page.vidhyarthi;

/**
 * @author Ravi Shankar
 *
 */
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.VyVidhyarthiDAO;
import org.vy.dal.dao.VyVidhyarthiDO;

import vy.org.app.common.AppConstants;
import vy.org.app.common.BaseAction;
import vy.org.app.common.ModeEnum;
import vy.org.app.common.ModuleEnum;

public class MntnVidhyarthiAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {

		MntnVidhyarthiForm form = (MntnVidhyarthiForm) actionForm;
		VyVidhyarthiDO dto = new VyVidhyarthiDO();

		if (form != null && form.getMode() != null) {
			if (ModeEnum.SEARCH.getName().equals(form.getMode())) {

				if (form.getVidhyarthiId() != null
						&& !"".equals(form.getVidhyarthiId().trim())) {
				
					dto.setVyId(form.getVidhyarthiId());

				}
				if (form.getVidhyalayaName() != null
						&& !"".equals(form.getVidhyalayaName().trim())) {

					dto.setVidhyalayaName(form.getVidhyalayaName());

				}
				if (form.getBatchNo() != null
						&& !"".equals(form.getBatchNo().trim())) {

					dto.setBatchNo(Long.parseLong(form.getBatchNo()));

				}
				if (form.getYearf() != null
						&& !"".equals(form.getYearf().trim())) {

					dto.setBatchFrom(form.getYearf());

				}
				if (form.getYeart() != null
						&& !"".equals(form.getYeart().trim())) {

					dto.setBatchTo(form.getYeart());

				}
				if (form.getRank() != null && !"".equals(form.getRank().trim())) {

					dto.setRankScore(form.getRank());

				}

				try {
					request.setAttribute(AppConstants.RESULT,
							VyVidhyarthiDAO.findByParam(dto));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			if (ModeEnum.ADD.getName().equals(form.getMode())) {

				if (form.getVidhyarthiId() != null
						&& !"".equals(form.getVidhyarthiId().trim())) {
				
					dto.setVyId(form.getVidhyarthiId());

				}
				if (form.getVidhyalayaName() != null
						&& !"".equals(form.getVidhyalayaName().trim())) {

					dto.setVidhyalayaName(form.getVidhyalayaName());

				}
				if (form.getBatchNo() != null
						&& !"".equals(form.getBatchNo().trim())) {

					dto.setBatchNo(Long.parseLong(form.getBatchNo()));

				}
				if (form.getYearf() != null
						&& !"".equals(form.getYearf().trim())) {

					dto.setBatchFrom(form.getYearf());

				}
				if (form.getYeart() != null
						&& !"".equals(form.getYeart().trim())) {

					dto.setBatchTo(form.getYeart());

				}
				if (form.getRank() != null && !"".equals(form.getRank().trim())) {

					dto.setRankScore(form.getRank());

				}

				try {
					VyVidhyarthiDAO.insert(dto);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {
		return ModuleEnum.SEARCH_VIDHYARTHI;
	}

}
